package com.wenwan.manage.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wenwan.manage.service.ReleaseTimesService;

import javax.annotation.Resource;

/**
 * 购买发布次数
 * 
 * @author Admin
 *
 */
@Controller
@RequestMapping(value = "/release/times")
public class ReleaseTimesController {

	@Resource
	private ReleaseTimesService releaseTimesService;

	/**
	 * 
	 * @param name
	 *            商品名
	 * @param price
	 *            单价
	 * @param discount
	 *            打折后
	 * @param times
	 *            获得的购买次数
	 * @param giveTimes
	 *            购买套餐后获得的赠送次数
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/create", method = { RequestMethod.POST })
	public Map<String, Object> create(@RequestParam(required = true) String name,
			@RequestParam(required = true) Double price, @RequestParam(required = true) Double discount,
			@RequestParam(required = true) Integer times, @RequestParam(required = true) Integer giveTimes) {
		return releaseTimesService.create(name, price, discount, times, giveTimes);
	}

	/**
	 * 删除
	 * 
	 * @param id
	 *            商品id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/delete/by/id", method = { RequestMethod.POST })
	public Map<String, Object> deleteById(@RequestParam(required = true) String id) {
		return releaseTimesService.deleteById(id);
	}

	/**
	 * 更新
	 * 
	 * @param id
	 *            商品id
	 * @param name
	 *            商品名
	 * @param price
	 *            单价
	 * @param discount
	 *            打折后
	 * @param times
	 *            获得的购买次数
	 * @param giveTimes
	 *            购买套餐后获得的赠送次数
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/update", method = { RequestMethod.POST })
	public Map<String, Object> update(@RequestParam(required = true) String id,
			@RequestParam(required = false) String name, @RequestParam(required = false) Double price,
			@RequestParam(required = false) Double discount, @RequestParam(required = false) Integer times,
			@RequestParam(required = false) Integer giveTimes) {
		return releaseTimesService.update(id, name, price, discount, times, giveTimes);
	}

	/**
	 * 查询所有
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/select/all", method = { RequestMethod.GET })
	public Map<String, Object> selectAll() {
		return releaseTimesService.selectAll();
	}

	/**
	 * 查询单个
	 * 
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/select/one/by/id", method = { RequestMethod.GET })
	public Map<String, Object> selectOneById(@RequestParam(required = true) String id) {
		return releaseTimesService.selectOneById(id);
	}

}
